package com.zlc.atonce.huarongdao.gui;

import com.zlc.atonce.huarongdao.algorithme.Node;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;

import java.util.List;

public class AnsPane extends BorderPane {
    private final IntegerProperty curStep = new SimpleIntegerProperty();

    List<String> allStep;
    private MyGrid gridPane = new MyGrid();
    private Button last = new Button("上一步");
    private Button next = new Button("下一步");

    public AnsPane(Node ans) {
        super();
        allStep = ans.toList();
        gridPane.updateByIdentity(allStep.get(0));
        setCenter(gridPane);

        Label label = new Label();
        setTop(label);
        setLeft(last);
        setRight(next);
        last.setOnAction(e -> {
            int i = curStep.get();
            curStep.setValue(i - 1);
            gridPane.updateByIdentity(allStep.get(i - 1));
        });
        next.setOnAction(e -> {
            int i = curStep.get();
            curStep.setValue(i + 1);
            gridPane.updateByIdentity(allStep.get(i + 1));
        });
        curStep.addListener((observableValue, number, t1) -> {
            label.setText(t1.toString());
            last.setDisable(t1.intValue() <= 0);
            next.setDisable(t1.intValue() >= allStep.size() - 1);
        });
    }


}
